package com.woniuxy.shiro.controller;

import com.woniuxy.entity.RbacManager;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.shiro.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/auth")
public class LoginController {
    @Autowired(required = false)
    LoginService loginService;
    //登录操作，直接去匹配数据库即可，不用自定义一个域
    @RequestMapping("/login")
    public ResponseEntity<RbacManager> login(@RequestBody RbacManager rbacManager){
        RbacManager rbacManager1 = loginService.login(rbacManager.getAccount(), rbacManager.getPassword());
        if(rbacManager1==null){
            //没有匹配成功
            return new ResponseEntity<RbacManager>(401,"登录失败",null);
        }else {
            //执行成功的业务
            return new ResponseEntity<RbacManager>(200,"登录成功",rbacManager1);
        }

    }
}
